#if FEATURE_INI
#define FILE_PATH "Uv_AAD\\Users\\%s.ini"
stock bool: CAccount::initializeHandler()
{
	return true;
}

stock bool: CAccount::loadPlayer(playerId) {
	new filePath[128];
	format(filePath, 128, FILE_PATH, nickName(playerId));

	if (!fexist(filePath))
		return false;
	
    format(playerData[playerId][ipAddress], 32, playerIP(playerId));
	INI_ParseFile(filePath, "CAccount_onLoad", .bExtra = true, .extra = playerId);
	return true;
}

stock bool: CAccount::checkAutoLogin(playerId) {
    if (adler32(playerData[playerId][ipAddress]) == ipHash(playerId))
		return true;
        
    return false;
}


stock CAccount::savePlayer(playerId) {
	new filePath[128];
	format(filePath, 128, FILE_PATH, nickName(playerId));
	
	new INI:playerFile = INI_Open(filePath);
	
	INI_WriteString(playerFile, "ip_address", playerData[playerId][ipAddress]);
	INI_WriteInt(playerFile, "kills", playerData[playerId][kills]);
	INI_WriteInt(playerFile, "deaths", playerData[playerId][deaths]);
	INI_WriteInt(playerFile, "level", playerData[playerId][level]);
	INI_WriteInt(playerFile, "bases_won", playerData[playerId][basesWon]);
	INI_WriteInt(playerFile, "bases_lost", playerData[playerId][basesLost]);
	INI_WriteInt(playerFile, "mvp", playerData[playerId][mvp]);
	
	INI_Close(playerFile);
}

stock CAccount::registerPlayer(playerId, const password[]) {
    new filePath[128];
    new passwordHash[129];
    
	format(filePath, 128, FILE_PATH, nickName(playerId));
	WP_Hash(passwordHash, 129, password);
    
    new INI:playerFile = INI_Open(filePath);
    INI_WriteString(playerFile, "password", passwordHash);
    INI_Close(playerFile);
    
    playerData[playerId][isRegistered] = true;
    playerData[playerId][isLogged] = true;
}

stock bool: CAccount::checkPassword(playerId, const password[]) {
	new passwordHash[129];
	WP_Hash(passwordHash, 129, password);
	
	if (strcmp(passwordHash, playerData[playerId][tempPassword], true) != 0)
		return false;
    
    playerData[playerId][isLogged] = true;
	return true;
}

forward CAccount::onLoad(playerId, name[], value[]);
public CAccount::onLoad(playerId, name[], value[]) {
	INI_String("password", playerData[playerId][tempPassword], 129);
	INI_String("ip_address", playerData[playerId][ipAddress], 32);
	
	INI_Int("kills", playerData[playerId][kills]);
	INI_Int("deaths", playerData[playerId][deaths]);
	INI_Int("level", playerData[playerId][level]);
	INI_Int("bases_won", playerData[playerId][basesWon]);
	INI_Int("bases_lost", playerData[playerId][basesLost]);
	INI_Int("mvp", playerData[playerId][mvp]);
    return true;
}
#endif
	